﻿
#region Using directives

using System;
using System.Collections;
using System.Collections.Specialized;


using System.Web.Configuration;
using System.Data;
using System.Data.Common;
using System.Configuration.Provider;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;

using bookMaster.AssetSystem.Entities;
using bookMaster.AssetSystem.Data;
using bookMaster.AssetSystem.Data.Bases;

#endregion

namespace bookMaster.AssetSystem.Data.SqlClient
{
	/// <summary>
	/// This class is the Sql implementation of the NetTiersProvider.
	/// </summary>
	public sealed class SqlNetTiersProvider : bookMaster.AssetSystem.Data.Bases.NetTiersProvider
	{
		private static object syncRoot = new Object();
		private string _applicationName;
        private string _connectionString;
        private bool _useStoredProcedure;
        string _providerInvariantName;
		
		/// <summary>
		/// Initializes a new instance of the <see cref="SqlNetTiersProvider"/> class.
		///</summary>
		public SqlNetTiersProvider()
		{	
		}		
		
		/// <summary>
        /// Initializes the provider.
        /// </summary>
        /// <param name="name">The friendly name of the provider.</param>
        /// <param name="config">A collection of the name/value pairs representing the provider-specific attributes specified in the configuration for this provider.</param>
        /// <exception cref="T:System.ArgumentNullException">The name of the provider is null.</exception>
        /// <exception cref="T:System.InvalidOperationException">An attempt is made to call <see cref="M:System.Configuration.Provider.ProviderBase.Initialize(System.String,System.Collections.Specialized.NameValueCollection)"></see> on a provider after the provider has already been initialized.</exception>
        /// <exception cref="T:System.ArgumentException">The name of the provider has a length of zero.</exception>
		public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "SqlNetTiersProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "NetTiers Sql provider");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            // Initialize _applicationName
            _applicationName = config["applicationName"];

            if (string.IsNullOrEmpty(_applicationName))
            {
                _applicationName = "/";
            }
            config.Remove("applicationName");


            #region "Initialize UseStoredProcedure"
            string storedProcedure  = config["useStoredProcedure"];
           	if (string.IsNullOrEmpty(storedProcedure))
            {
                throw new ProviderException("Empty or missing useStoredProcedure");
            }
            this._useStoredProcedure = Convert.ToBoolean(config["useStoredProcedure"]);
            config.Remove("useStoredProcedure");
            #endregion

			#region ConnectionString

			// Initialize _connectionString
			_connectionString = config["connectionString"];
			config.Remove("connectionString");

			string connect = config["connectionStringName"];
			config.Remove("connectionStringName");

			if ( String.IsNullOrEmpty(_connectionString) )
			{
				if ( String.IsNullOrEmpty(connect) )
				{
					throw new ProviderException("Empty or missing connectionStringName");
				}

				if ( DataRepository.ConnectionStrings[connect] == null )
				{
					throw new ProviderException("Missing connection string");
				}

				_connectionString = DataRepository.ConnectionStrings[connect].ConnectionString;
			}

            if ( String.IsNullOrEmpty(_connectionString) )
            {
                throw new ProviderException("Empty connection string");
			}

			#endregion
            
             #region "_providerInvariantName"

            // initialize _providerInvariantName
            this._providerInvariantName = config["providerInvariantName"];

            if (String.IsNullOrEmpty(_providerInvariantName))
            {
                throw new ProviderException("Empty or missing providerInvariantName");
            }
            config.Remove("providerInvariantName");

            #endregion

        }
		
		/// <summary>
		/// Creates a new <c cref="TransactionManager"/> instance from the current datasource.
		/// </summary>
		/// <returns></returns>
		public override TransactionManager CreateTransaction()
		{
			return new TransactionManager(this._connectionString);
		}
		
		/// <summary>
		/// Gets a value indicating whether to use stored procedure or not.
		/// </summary>
		/// <value>
		/// 	<c>true</c> if this repository use stored procedures; otherwise, <c>false</c>.
		/// </value>
		public bool UseStoredProcedure
		{
			get {return this._useStoredProcedure;}
			set {this._useStoredProcedure = value;}
		}
		
		 /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>The connection string.</value>
		public string ConnectionString
		{
			get {return this._connectionString;}
			set {this._connectionString = value;}
		}
		
		/// <summary>
	    /// Gets or sets the invariant provider name listed in the DbProviderFactories machine.config section.
	    /// </summary>
	    /// <value>The name of the provider invariant.</value>
	    public string ProviderInvariantName
	    {
	        get { return this._providerInvariantName; }
	        set { this._providerInvariantName = value; }
	    }		
		
		///<summary>
		/// Indicates if the current <c cref="NetTiersProvider"/> implementation supports Transacton.
		///</summary>
		public override bool IsTransactionSupported
		{
			get
			{
				return true;
			}
		}

		
		#region "RecursosProvider"
			
		private SqlRecursosProvider innerSqlRecursosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Recursos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override RecursosProviderBase RecursosProvider
		{
			get
			{
				if (innerSqlRecursosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlRecursosProvider == null)
						{
							this.innerSqlRecursosProvider = new SqlRecursosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlRecursosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlRecursosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlRecursosProvider SqlRecursosProvider
		{
			get {return RecursosProvider as SqlRecursosProvider;}
		}
		
		#endregion
		
		
		#region "PedidosProvider"
			
		private SqlPedidosProvider innerSqlPedidosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Pedidos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override PedidosProviderBase PedidosProvider
		{
			get
			{
				if (innerSqlPedidosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlPedidosProvider == null)
						{
							this.innerSqlPedidosProvider = new SqlPedidosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlPedidosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlPedidosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlPedidosProvider SqlPedidosProvider
		{
			get {return PedidosProvider as SqlPedidosProvider;}
		}
		
		#endregion
		
		
		#region "TiposRecursosProvider"
			
		private SqlTiposRecursosProvider innerSqlTiposRecursosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="TiposRecursos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override TiposRecursosProviderBase TiposRecursosProvider
		{
			get
			{
				if (innerSqlTiposRecursosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlTiposRecursosProvider == null)
						{
							this.innerSqlTiposRecursosProvider = new SqlTiposRecursosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlTiposRecursosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlTiposRecursosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlTiposRecursosProvider SqlTiposRecursosProvider
		{
			get {return TiposRecursosProvider as SqlTiposRecursosProvider;}
		}
		
		#endregion
		
		
		#region "LibrosProvider"
			
		private SqlLibrosProvider innerSqlLibrosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Libros"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override LibrosProviderBase LibrosProvider
		{
			get
			{
				if (innerSqlLibrosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlLibrosProvider == null)
						{
							this.innerSqlLibrosProvider = new SqlLibrosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlLibrosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlLibrosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlLibrosProvider SqlLibrosProvider
		{
			get {return LibrosProvider as SqlLibrosProvider;}
		}
		
		#endregion
		
		
		#region "UsuariosProvider"
			
		private SqlUsuariosProvider innerSqlUsuariosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Usuarios"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UsuariosProviderBase UsuariosProvider
		{
			get
			{
				if (innerSqlUsuariosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUsuariosProvider == null)
						{
							this.innerSqlUsuariosProvider = new SqlUsuariosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUsuariosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUsuariosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUsuariosProvider SqlUsuariosProvider
		{
			get {return UsuariosProvider as SqlUsuariosProvider;}
		}
		
		#endregion
		
		
		#region "UsuariosRecursosProvider"
			
		private SqlUsuariosRecursosProvider innerSqlUsuariosRecursosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="UsuariosRecursos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override UsuariosRecursosProviderBase UsuariosRecursosProvider
		{
			get
			{
				if (innerSqlUsuariosRecursosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlUsuariosRecursosProvider == null)
						{
							this.innerSqlUsuariosRecursosProvider = new SqlUsuariosRecursosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlUsuariosRecursosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlUsuariosRecursosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlUsuariosRecursosProvider SqlUsuariosRecursosProvider
		{
			get {return UsuariosRecursosProvider as SqlUsuariosRecursosProvider;}
		}
		
		#endregion
		
		
		#region "ProveedoresProvider"
			
		private SqlProveedoresProvider innerSqlProveedoresProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Proveedores"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ProveedoresProviderBase ProveedoresProvider
		{
			get
			{
				if (innerSqlProveedoresProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlProveedoresProvider == null)
						{
							this.innerSqlProveedoresProvider = new SqlProveedoresProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlProveedoresProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlProveedoresProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlProveedoresProvider SqlProveedoresProvider
		{
			get {return ProveedoresProvider as SqlProveedoresProvider;}
		}
		
		#endregion
		
		
		#region "ClientesProvider"
			
		private SqlClientesProvider innerSqlClientesProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Clientes"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override ClientesProviderBase ClientesProvider
		{
			get
			{
				if (innerSqlClientesProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlClientesProvider == null)
						{
							this.innerSqlClientesProvider = new SqlClientesProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlClientesProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlClientesProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlClientesProvider SqlClientesProvider
		{
			get {return ClientesProvider as SqlClientesProvider;}
		}
		
		#endregion
		
		
		#region "CiudadesProvider"
			
		private SqlCiudadesProvider innerSqlCiudadesProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Ciudades"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CiudadesProviderBase CiudadesProvider
		{
			get
			{
				if (innerSqlCiudadesProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCiudadesProvider == null)
						{
							this.innerSqlCiudadesProvider = new SqlCiudadesProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCiudadesProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlCiudadesProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCiudadesProvider SqlCiudadesProvider
		{
			get {return CiudadesProvider as SqlCiudadesProvider;}
		}
		
		#endregion
		
		
		#region "CatalogoProvider"
			
		private SqlCatalogoProvider innerSqlCatalogoProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="Catalogo"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override CatalogoProviderBase CatalogoProvider
		{
			get
			{
				if (innerSqlCatalogoProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlCatalogoProvider == null)
						{
							this.innerSqlCatalogoProvider = new SqlCatalogoProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlCatalogoProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlCatalogoProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlCatalogoProvider SqlCatalogoProvider
		{
			get {return CatalogoProvider as SqlCatalogoProvider;}
		}
		
		#endregion
		
		
		#region "DetallePedidosProvider"
			
		private SqlDetallePedidosProvider innerSqlDetallePedidosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="DetallePedidos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override DetallePedidosProviderBase DetallePedidosProvider
		{
			get
			{
				if (innerSqlDetallePedidosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlDetallePedidosProvider == null)
						{
							this.innerSqlDetallePedidosProvider = new SqlDetallePedidosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlDetallePedidosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlDetallePedidosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlDetallePedidosProvider SqlDetallePedidosProvider
		{
			get {return DetallePedidosProvider as SqlDetallePedidosProvider;}
		}
		
		#endregion
		
		
		#region "HistoricoPedidosProvider"
			
		private SqlHistoricoPedidosProvider innerSqlHistoricoPedidosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="HistoricoPedidos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override HistoricoPedidosProviderBase HistoricoPedidosProvider
		{
			get
			{
				if (innerSqlHistoricoPedidosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlHistoricoPedidosProvider == null)
						{
							this.innerSqlHistoricoPedidosProvider = new SqlHistoricoPedidosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlHistoricoPedidosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlHistoricoPedidosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlHistoricoPedidosProvider SqlHistoricoPedidosProvider
		{
			get {return HistoricoPedidosProvider as SqlHistoricoPedidosProvider;}
		}
		
		#endregion
		
		
		#region "HistoricoDetallePedidosProvider"
			
		private SqlHistoricoDetallePedidosProvider innerSqlHistoricoDetallePedidosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="HistoricoDetallePedidos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override HistoricoDetallePedidosProviderBase HistoricoDetallePedidosProvider
		{
			get
			{
				if (innerSqlHistoricoDetallePedidosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlHistoricoDetallePedidosProvider == null)
						{
							this.innerSqlHistoricoDetallePedidosProvider = new SqlHistoricoDetallePedidosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlHistoricoDetallePedidosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlHistoricoDetallePedidosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlHistoricoDetallePedidosProvider SqlHistoricoDetallePedidosProvider
		{
			get {return HistoricoDetallePedidosProvider as SqlHistoricoDetallePedidosProvider;}
		}
		
		#endregion
		
		
		#region "EstadoPedidosProvider"
			
		private SqlEstadoPedidosProvider innerSqlEstadoPedidosProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="EstadoPedidos"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override EstadoPedidosProviderBase EstadoPedidosProvider
		{
			get
			{
				if (innerSqlEstadoPedidosProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlEstadoPedidosProvider == null)
						{
							this.innerSqlEstadoPedidosProvider = new SqlEstadoPedidosProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlEstadoPedidosProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlEstadoPedidosProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlEstadoPedidosProvider SqlEstadoPedidosProvider
		{
			get {return EstadoPedidosProvider as SqlEstadoPedidosProvider;}
		}
		
		#endregion
		
		
		
		#region "MenusAccesiblesProvider"
		
		private SqlMenusAccesiblesProvider innerSqlMenusAccesiblesProvider;

		///<summary>
		/// This class is the Data Access Logic Component for the <see cref="MenusAccesibles"/> business entity.
		/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
		///</summary>
		/// <value></value>
		public override MenusAccesiblesProviderBase MenusAccesiblesProvider
		{
			get
			{
				if (innerSqlMenusAccesiblesProvider == null) 
				{
					lock (syncRoot) 
					{
						if (innerSqlMenusAccesiblesProvider == null)
						{
							this.innerSqlMenusAccesiblesProvider = new SqlMenusAccesiblesProvider(_connectionString, _useStoredProcedure, _providerInvariantName);
						}
					}
				}
				return innerSqlMenusAccesiblesProvider;
			}
		}
		
		/// <summary>
		/// Gets the current <c cref="SqlMenusAccesiblesProvider"/>.
		/// </summary>
		/// <value></value>
		public SqlMenusAccesiblesProvider SqlMenusAccesiblesProvider
		{
			get {return MenusAccesiblesProvider as SqlMenusAccesiblesProvider;}
		}
		
		#endregion
		
		
		#region "General data access methods"

		#region "ExecuteNonQuery"
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper);	
			
		}

		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		public override void ExecuteNonQuery(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			database.ExecuteNonQuery(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteNonQuery(commandType, commandText);	
		}
		/// <summary>
		/// Executes the non query.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override int ExecuteNonQuery(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteNonQuery(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataReader"
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteReader(commandWrapper);	
		}

		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteReader(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteReader(commandType, commandText);	
		}
		/// <summary>
		/// Executes the reader.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override IDataReader ExecuteReader(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteReader(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteDataSet"
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteDataSet(commandWrapper);	
		}

		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteDataSet(commandWrapper, transactionManager.TransactionObject);	
		}


		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteDataSet(commandType, commandText);	
		}
		/// <summary>
		/// Executes the data set.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override DataSet ExecuteDataSet(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteDataSet(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#region "ExecuteScalar"
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(string storedProcedureName, params object[] parameterValues)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="storedProcedureName">Name of the stored procedure.</param>
		/// <param name="parameterValues">The parameter values.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, string storedProcedureName, params object[] parameterValues)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(transactionManager.TransactionObject, storedProcedureName, parameterValues);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(DbCommand commandWrapper)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);			
			return database.ExecuteScalar(commandWrapper);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandWrapper">The command wrapper.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, DbCommand commandWrapper)
		{
			Database database = transactionManager.Database;
			return database.ExecuteScalar(commandWrapper, transactionManager.TransactionObject);	
		}

		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(CommandType commandType, string commandText)
		{
			SqlDatabase database = new SqlDatabase(this._connectionString);
			return database.ExecuteScalar(commandType, commandText);	
		}
		/// <summary>
		/// Executes the scalar.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="commandType">Type of the command.</param>
		/// <param name="commandText">The command text.</param>
		/// <returns></returns>
		public override object ExecuteScalar(TransactionManager transactionManager, CommandType commandType, string commandText)
		{
			Database database = transactionManager.Database;			
			return database.ExecuteScalar(transactionManager.TransactionObject , commandType, commandText);				
		}
		#endregion

		#endregion


	}
}
